<?php 
namespace Admin\Model;
use Think\Model;
class FaqsModel extends Model{ 
	/* 客户模型自动验证 */
	protected $_validate = array(
        array('questions','require','问题必须填写'),
		array('type','require','类型必填'),	
		array('answers','require','答案必须填写'),
    );  
	/* 自动完成规则 */
	protected $_auto = array(
			array('questions', 'htmlspecialchars', self::MODEL_BOTH, 'function'),
			array('type', 'htmlspecialchars', self::MODEL_BOTH, 'function'),
			array('answers', 'htmlspecialchars', self::MODEL_BOTH, 'function'), 
	);
    public function update() {
    	
    	/* 获取数据对象 */
    	$data = $this->create ( $_POST );
    	if (empty ( $data )) {
    		return false;
    	} 
    	/* 添加*/
    	if (empty ( $data ['id'] )) {
    		$id = $this->add();
    		if (! $id) {
    			$this->error = '新增出错！';
    			return false;
    		}
    	} else {
    		$status = $this->save (); 
    		if (false === $status) {
    			$this->error = '更新出错！';
    			return false;
    		}
    	}
    	return $data;
    	
    } 
}